package common.system.action;

import java.util.List;

import com.opensymphony.xwork2.ActionSupport;
import common.system.bean.Area;
import common.system.bean.City;
import common.system.service.AreaService;
import common.system.service.CityService;

public class AreaAction extends ActionSupport {
	private CityService cityService;
	private AreaService areaService;
	private static final long serialVersionUID = 1L;
	private int id;
	private String name;
	private int cityId;
	private String resultStr;
	private String resultCode;
	private List<Area> list;
	public String addArea(){
		if(cityId==0){
			resultStr = "界面出错，请联系管理员！";
			resultCode="0";
			return SUCCESS;
		}
		City city = this.cityService.getCityByID(cityId);
		if(city==null){
			resultStr = "界面传递的城市码出错，请联系管理员！";
			resultCode="0";
			return SUCCESS;
		}
		Area area = new Area();
		area.setCity(city);
		area.setName(name);
		boolean result = this.areaService.addArea(area);
		if(result){
			resultCode="1";
			return SUCCESS;
			
		}else{
			resultStr = "区域信息存进数据库出错！";
			resultCode="0";
			return SUCCESS;
		}
	}
	
	public String updateArea(){
		return SUCCESS;
	}
	public String queryAreaByCity(){
		if(cityId==0){
			resultStr = "界面出错，请联系管理员！";
			resultCode="0";
			return SUCCESS;
		}
		//这个接口不会返回空值
		list = this.areaService.getAreaByCityId(cityId);
		resultCode="1";
		return SUCCESS; 
	}
	//======getter and setter方法
	
	public int getId() {
		return id;
	}
	public List<Area> getList() {
		return list;
	}

	public void setList(List<Area> list) {
		this.list = list;
	}

	public String getResultStr() {
		return resultStr;
	}
	public void setResultStr(String resultStr) {
		this.resultStr = resultStr;
	}
	public String getResultCode() {
		return resultCode;
	}
	public void setResultCode(String resultCode) {
		this.resultCode = resultCode;
	}
	public CityService getCityService() {
		return cityService;
	}
	public void setCityService(CityService cityService) {
		this.cityService = cityService;
	}
	public AreaService getAreaService() {
		return areaService;
	}
	public void setAreaService(AreaService areaService) {
		this.areaService = areaService;
	}
	public int getCityId() {
		return cityId;
	}
	public void setCityId(int cityId) {
		this.cityId = cityId;
	}
	public void setId(int id) {
		this.id = id;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	
}
